package com.zry.fertilizer.view

import android.app.Activity
import android.support.v7.widget.RecyclerView
import android.widget.LinearLayout
import com.zry.fertilizer.R
import com.zry.fertilizer.animation.RecyclerViewUtilKt
import com.zry.fertilizer.been.PutState

class PutStatePopup(context: Activity?, linearLayout: LinearLayout, putStateList: MutableList<PutState>) : BasePopup(context!!, R.layout.document_status_popup, linearLayout) {

    init {
        val documentStatusRecycler: RecyclerView = contentView!!.findViewById(R.id.documentStatusRecycler)
        val recyclerViewUtilKt = RecyclerViewUtilKt(context!!, documentStatusRecycler)
        recyclerViewUtilKt.initRecyclerView()
        val putStorageAdapter = PutStorageAdapter(R.layout.item_document_status_popup, putStateList)
        recyclerViewUtilKt.setAdapter(putStorageAdapter)
        putStorageAdapter.setOnItemClickListener { adapter, view, position ->
            if (listener != null) {
                listener?.handleResult(putStateList[position])
            }
            popupWindow?.dismiss()
        }
    }


    private var listener: PutStatePopup.PutStateListener? = null

    interface PutStateListener {
        fun handleResult(putState: PutState)
    }

    fun setListener(listener: PutStatePopup.PutStateListener): PutStatePopup {
        this.listener = listener
        return this
    }
}